package number_53;

public class Solution {
    public int maxSubArray(int[] nums) {
        int pre = 0, maxAns = nums[0];
        for (int v : nums) {
            pre = Math.max(pre + v, v);
            maxAns = Math.max(maxAns, pre);
        }
        return maxAns;
    }

    public static void main(String[] args) {
        new Solution().maxSubArray(new int[] {-2, 1, -3, 4, -1, 2, 1, -5, 4});
    }
}
